# gRPC协议编译配置
# 注意：Protobuf和gRPC已经在主CMakeLists.txt中查找
# 这里直接使用父作用域的变量

# 生成gRPC代码
set(PROTO_FILES
    service_rpc.proto
)

# 添加库目标
add_library(service_rpc_proto ${PROTO_FILES})

# 链接依赖
target_link_libraries(service_rpc_proto
    PUBLIC
        protobuf::libprotobuf
        gRPC::grpc++
        gRPC::grpc++_reflection
)

# 设置生成文件路径
target_include_directories(service_rpc_proto
    PUBLIC
        ${CMAKE_CURRENT_BINARY_DIR}
)

# 生成C++代码
protobuf_generate(
    TARGET service_rpc_proto
    LANGUAGE cpp
    PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
)

# 生成gRPC代码
protobuf_generate(
    TARGET service_rpc_proto
    LANGUAGE grpc
    GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
    PLUGIN "protoc-gen-grpc=\$<TARGET_FILE:gRPC::grpc_cpp_plugin>"
    PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
)
